package com.ecust.ml.cardriving.model;

import com.ecust.ml.cardriving.view.CarDrivingSimulator;

public class Car {
	
	/**
	 * 慢速，
	 */
	public static final int SPEED_SLOW 		= 25;
	/**
	 * 中速，
	 */
	public static final int SPEED_MEDIUM 	= 28;
	/**
	 * 快速，
	 */
	public static final int SPEED_FAST 		= 32;
	
	/**
	 * 目标小车初始速度：60km/h
	 */
	public static final int SPEED_INIT 		= 35;

	/**
	 * 小车速度最小值
	 */
	public static final int SPEED_MIN		= 0;
	
	/**
	 * 小车速度最大值
	 */
	public static final int SPEED_MAX 		= 100;
	
	/**
	 * 车身长度
	 */
	public static final int CAR_LENGTH 		= 25;
	
	/**
	 * 车身宽度
	 */
	public static final int CAR_WIDTH 		= 15;
	
	/**
	 * 测试车辆行驶位置（范围：0-500）
	 */
	public static final int CAR_RUN_POSITION = 200;
	
	/**
	 * 速度
	 */
	private int speed = SPEED_SLOW;
	
	/**
	 * 车身长度（与冲突检测有关）
	 */
	private int length = CAR_LENGTH;
	
	/**
	 * 所在车道(1,2,3)
	 */
	private int laneOn = Highway.LANE_MIDDLE;
	
	/**
	 * 屏幕中位置(0 ~ 600，200代表碰撞) 
	 */
	private int position = CarDrivingSimulator.HEIGHT;
	
	public Car(int laneOn) {
		if(laneOn == Highway.LANE_LEFT) {
			this.laneOn = laneOn;
			this.speed = SPEED_FAST;
			this.position = CarDrivingSimulator.WIDTH;
		} else if(laneOn == Highway.LANE_RIGHT) {
			this.laneOn = laneOn;
			this.speed = SPEED_SLOW;
			this.position = CarDrivingSimulator.WIDTH;
		} else {
			this.laneOn = laneOn;
			this.speed = SPEED_MEDIUM;
			this.position = CarDrivingSimulator.WIDTH;
		}
		
	}
	
	public Car(int laneOn, int speed) {
		this.laneOn = laneOn;
		this.speed = speed;
		this.position = CarDrivingSimulator.WIDTH;
	}
	
	public Car(int laneOn, int speed, int position) {
		this.laneOn = laneOn;
		this.speed = speed;
		this.position = position;
	}
	
	/**
	 * 加速
	 */
	public void speedUp() {
		int newSpeed = this.speed;
		newSpeed += 5;
		if(newSpeed > SPEED_MAX) {
			newSpeed = SPEED_MAX;
		}
		this.speed = newSpeed;
	}
	
	/**
	 * 减速
	 */
	public void slowDown() {
		int newSpeed = this.speed;
		newSpeed -= 5;
		if(newSpeed < SPEED_MIN) {
			newSpeed = SPEED_MIN;
		}
		this.speed = newSpeed;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getLaneOn() {
		return laneOn;
	}

	public void setLaneOn(int laneOn) {
		this.laneOn = laneOn;
	}

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}
	
}
